//
//  SLNavigationDelegate.m
//  CustomNavigationTransition
//
//  Created by 朱志佳 on 2019/4/3.
//  Copyright © 2019 朱志佳. All rights reserved.
//

#import "SLNavigationDelegate.h"
#import "SlideAnimationController.h"

@implementation SLNavigationDelegate

- (instancetype)init
{
    self = [super init];
    if (self) {
        NSLog(@"%@##%@",NSStringFromClass([self class]),NSStringFromSelector(_cmd));
        _interactive = false;
        _interactionController = [[UIPercentDrivenInteractiveTransition alloc] init];
    }
    return self;
}

- (nullable id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
                                   interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController NS_AVAILABLE_IOS(7_0){
    NSLog(@"%@##%@",NSStringFromClass([self class]),NSStringFromSelector(_cmd));
    return _interactive ? _interactionController : nil;
}

- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
                                            animationControllerForOperation:(UINavigationControllerOperation)operation
                                                         fromViewController:(UIViewController *)fromVC
                                                           toViewController:(UIViewController *)toVC  NS_AVAILABLE_IOS(7_0){
    NSLog(@"%@##%@",NSStringFromClass([self class]),NSStringFromSelector(_cmd));
    NSUInteger transitionType = operation;
    
    //-z 定制 operation方式
//    if ([toVC isKindOfClass:NSClassFromString(@"SecondViewController")]) {
//        transitionType = TransitionTypePresentation;
//    }
    
    if (transitionType == UINavigationControllerOperationPush) {
        transitionType = TransitionTypePresentation;
    }
    if (transitionType == UINavigationControllerOperationPop) {
        transitionType = TransitionTypeDismisssal;
    }
    
    SlideAnimationController *slide = [[SlideAnimationController alloc] init];
    slide.transitionType = transitionType;
    return slide;
}

@end
